#ifndef GAMESTATE_H
#define GAMESTATE_H
#include <SFML/Graphics.hpp>
#include <Thor/Animation.hpp>
#include "Globals.h"
#include "Panel.h"
#include "Ball.h"
#include "Level.h"
#include "State.h"
#include "GameoverState.h"
#include <fstream>
#include <Thor/Time/StopWatch.hpp>

class DevConsole
{
    public:
        DevConsole();
        void draw(Level* level, sf::RenderWindow* window);
        bool enabled;

    private:
        sf::Text bricksText;
        sf::Text ballText;
        sf::Text bonusesText;
        sf::Text fpsText;
        sf::Clock frameClock;
};


class GameState : public sfge::State
{
    public:
        void init();
        void cleanup();

        void draw();
        void update();
        void handle();

        void resume(){};
        void pause(){};

        static GameState* Instance(sf::RenderWindow* window, sfge::StateManager* mgr)
       	{
       	    if(gameState == NULL)
                gameState = new GameState(window, mgr);
            return gameState;
        }


    private:
        GameState(sf::RenderWindow* window, sfge::StateManager* mgr);
        ~GameState();

        void updateText();
        void initAni();
        void reset();
        void loadLevels();
        void saveStats();
        void resetStats();

        sf::Sprite background;
        sf::Sprite infoBackground;
        sf::Sprite heart;
        sf::Sprite pauseSprite;
        sf::Sprite closingPanel1;
        sf::Sprite closingPanel2;
        thor::StopWatch clock;
        thor::StopWatch playTimeClock;
        sf::Clock frameClock;
        sf::Text scoreText;
        std::vector<Level*> levels;
        int currentLvl;
        int accumulator;
        long totalTime;
        bool newLevel;
        DevConsole devConsole;
        static GameState* gameState;
};

#endif // GAMESTATE_H
